//
//  WYMessageListController.m
//  Boss
//
//  Created by admin on 2018/8/14.
//  Copyright © 2018年 admin. All rights reserved.
//

#import "WYMessageListController.h"
#import "WYMessageListCell.h"
#import "WYMessageListModel.h"
#import "WYMessageController.h"
#import "WYCommentMeCell.h"
#import "WYForwardMeController.h"
#import "WYCommentMeController.h"
#import "WYFollowMeController.h"
#import "CJChatController.h"
@interface WYMessageListController ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic,strong)UITableView *tableView;
@property (nonatomic,strong) NSArray *dataArray;
@property (nonatomic,strong) NSArray *countArray;
@end

@implementation WYMessageListController
-(NSArray *)countArray
{
    if (!_countArray) {
        _countArray = @[@"",@"",@"",@"",@""];
    }
    return _countArray;
}
-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [self loadMessageCount];
}
-(void)loadMessageCount
{
    WEAKSELF
    [WYHttpServer seeAllUnreadNumberByTypeSucessBlock:^(BOOL success, id response, NSString *errorMessage) {
        if (success) {
            weakSelf.countArray = @[[response[@"result"][@"sysMessageNumber"] stringValue],[response[@"result"][@"commentMessageNumber"] stringValue],[response[@"result"][@"followMessageNumber"] stringValue],[response[@"result"][@"forwardMessageNumber"] stringValue]];
            [weakSelf.tableView reloadData];
        }
        
        
    }];
    
    
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.dataArray = [WYMessageListModel getMessageModel];
    [self setupUI];
}
-(void)setupUI
{
    self.navigationItem.title = @"消息";
    [self.view addSubview:self.tableView];
    [self.tableView registerNib:[UINib nibWithNibName:@"WYMessageListCell" bundle:nil] forCellReuseIdentifier:@"WYMessageListCell"];
    self.tableView.rowHeight = 78;
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.dataArray.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    WYMessageListCell *cell = [tableView dequeueReusableCellWithIdentifier:@"WYMessageListCell" forIndexPath:indexPath];
    if (!cell) {
        cell = [[NSBundle mainBundle]loadNibNamed:@"WYMessageListCell" owner:nil options:nil].firstObject;
    }
    WYMessageListModel *model = self.dataArray[indexPath.row];
    cell.messageImageview.image = [UIImage imageNamed:model.imageName];
    cell.nameLabel.text = model.name;
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    [cell setCount:self.countArray[indexPath.row]];
    return cell;    
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    if (indexPath.row==0) {
        WYMessageController *mvc = [[WYMessageController alloc]init];
        [self.navigationController pushViewController:mvc animated:YES];
    }
    if (indexPath.row==1) {
        WYCommentMeController *cmc = [[WYCommentMeController alloc]init];
        [self.navigationController pushViewController:cmc animated:YES];
    }
    if (indexPath.row==2) {
        WYFollowMeController *fvc = [[WYFollowMeController alloc]init];
        [self.navigationController pushViewController:fvc animated:YES];
    }
    if (indexPath.row==3) {
        WYForwardMeController *fvc = [[WYForwardMeController alloc]init];
        [self.navigationController pushViewController:fvc animated:YES];
    }
    if (indexPath.row == 4) {
        CJChatController *cvc = [[CJChatController alloc]init];
        
        [self.navigationController pushViewController:cvc animated:YES];
    }
    
    
    
    
    
}




-(UITableView *)tableView
{
    if (!_tableView) {
        _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, self.navHeight+10, kScreenWidth, kScreenHeight) style:(UITableViewStylePlain)];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        [_tableView setSeparatorStyle:(UITableViewCellSeparatorStyleNone)];
        _tableView.backgroundColor = [UIColor hexStringToColor:@"#f7f7f7" alpha:1.0];
    }
    return _tableView;
}

@end
